package com.fanfeifei.web.controller;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.fanfeifei.web.domain.mapper.SampleUserMapper;
import com.fanfeifei.web.domain.model.SampleUser;

@Controller
@RequestMapping("/sample")
public class SampleController {	
	@Autowired
	@Qualifier("sampleUserMapper")
	private SampleUserMapper dao;
	
	
	@RequestMapping(method=RequestMethod.GET, value="/hello/{param}")
	public String sample(@PathVariable String param,Model model){
		model.addAttribute("message", "Hello "+param+"!");
		
		SampleUser gay = new SampleUser();
		gay.setAccount(param);
		gay.setFunction("func"+param) ;
		gay.setPassword("pass"+param) ;
		
		dao.insertUser(gay);
		
		List<SampleUser> user=dao.selectUser();
		user.get(0).setPassword("udate uto "+param);
		dao.updateUser(user.get(0));
		user=dao.selectUser();
		dao.deleteUser(user.get(user.size()-1));
		
		user = null;
		user = dao.selectUserAll();
		
		model.addAttribute("users", user);
		
        return "helloworld";
	}
}
